<extend name="layout/main" />

<block name="HEADER">
	<style type="text/css">
		.layui-layer-page .layui-layer-content{
			overflow: initial;
		}
		#grid .layui-table-view .layui-table td .layui-table-cell{
			height: 36px;
		    line-height: 36px;
		}
		#grid .layui-btn+.layui-btn {
		    margin-left: 0;
		}
	</style>
</block>

<block name="CONTENT">
	<div class="wrapper">
		<div class="panel-heading">
			<control:search id="searchs" />
		</div>
		<div class="content">
			<control:grid id="grid" padding="0" height="100%" />
		</div>
	</div>
</block>

<block name="FOOTER">
	<script type="text/javascript">
		var page = (function(ns){
     
		    //页面初始化
		    ns.init=function(){
		        ns.query();
		    }
		    
		    //搜索事件
		    ns.query=function(){
		    	grid.load( searchs.getData() );
		    }
		    
		    //新增
		    ns.add=function(){
		    	var filter = {
		            url:"modules/coupon/set/edit",
		            oid:"",
		            mode:1
		        }
		        $.openIframe(filter, "新增",['500px', '550px']);
		    }
		    
		    //编辑
		    ns.edit=function(){
		    	var selectedRow = grid.getSelectedRows()[0];
		        var filter = {
		            url:"modules/coupon/set/edit",
		            oid: selectedRow.id ,
		            mode:2
		        }
		        $.openIframe(filter, "编辑",['500px', '550px']);
		    }  
		    
		    //删除
		    ns.del =function(){
		    	if( !grid.isSelected() ){
		    		return false;
		    	}
		    	$.confirm("确定删除？", function(){
		    		$.ajaxs('/admin/v1/coupon/del',{
			    		ids:grid.getSelectedColumnValue('id')
			    	},function(res){
			    		$.toast(1,"已删除！");
			    		grid.load();
			    	});
		    	});
		    }
		    
		    //下拉移动  type: 1 = 上移 ,  type: 2 = 下移
		    ns.move = function(type){
		    	grid.adjustSort(type,"sort_no");
		    }
		    
		    //启用禁用
		    ns.setEnable =function(state){
		    	if( !grid.isSelected() ){
		    		return false;
		    	}
		    	$.confirm("确定" + (state == "0" ? "禁用?" : "启用?"),function(index){
			    	$.ajaxs("/admin/v1/coupon/setEnable",{
			    	 	ids: grid.getSelectedColumnValue("id"),
			    	 	state: state 
			    	},function(res){
			            grid.load();      
			        });
			        layer.close(index);
		        });
		    }
		    
		    
		    //打开地推明细
		    ns.openDetailed =function(state){
		    	if( !grid.isSelected() ){
		    		return false;
		    	}
		        var filter = {
		            url:"modules/spreadMng/list/detailed",
		            oid: grid.getSelectedColumnValue("id"),
		            spread_id: grid.getSelectedColumnValue("spread_id"),
		            mode:2
		        }
		        $.openIframe(filter, "地推明细",['800px', '520px']);
		    }
		    
		    
		    //发布
		    ns.release =function(state){
		    	if( !grid.isSelected() ){
		    		return false;
		    	}
		        var filter = {
		            url:"modules/coupon/set/release",
		            oid: grid.getSelectedColumnValue("id"),
		            name: grid.getSelectedColumnValue("name"),
		            price: grid.getSelectedColumnValue("price"),
		            remark: grid.getSelectedColumnValue("remark"),
		            mode:1
		        }
		        $.openIframe(filter, "发布",['600px', '550px']);
		    }
		    
		    //预览海报
		    ns.generatePoster =function(id){
		    	layer.photos({
		    		anim: 5 ,
				    photos: {
						data: [{
					    	"src": __root__+"/index.php/admin/v1/coupon/generatePoster?cid="+id
						}]
				    }
				});
		    }
		    
		    return ns;
		}({}));
		
		
		$(function(){ page.init();  });

	</script>
</block>